//
//  DFForumController.m
//  DFront
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 xuzenghui. All rights reserved.
//

#import "DFForumController.h"
#import "HotPostTableViewController.h"
#import "DFPartViewController.h"


@interface DFForumController ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *forumScrView;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *aline;

@end

@implementation DFForumController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    [self.view addSubview:self.topView];
    self.view.frame = CGRectMake(0, 64, kScreenWidth, kScreenHeight - 64 - 44);
    self.view.backgroundColor = [UIColor whiteColor];
    [self addForumScrollView];
    _forumScrView.delegate = self;
    HotPostTableViewController *HotPostVC = [[HotPostTableViewController alloc] init];
    [self addChildViewController:HotPostVC];
    HotPostVC.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64);
    [_forumScrView addSubview:HotPostVC.view];
    DFPartViewController *partVC = [[DFPartViewController alloc] init];
    [self addChildViewController:partVC];
    partVC.view.frame = CGRectMake(kScreenWidth, 0, kScreenWidth, kScreenHeight - 44);
    [_forumScrView addSubview:partVC.view];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setTitle:@"热帖" forState:UIControlStateNormal];
    btn1.frame = CGRectMake(kScreenWidth / 2 - 70, 7, 40, 28);
    btn1.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.topView addSubview:btn1];
    [btn1 addTarget:self action:@selector(one:) forControlEvents:UIControlEventTouchUpInside];
    _line = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 70, 37, 40, 2)];
    _line.backgroundColor = [UIColor whiteColor];
    [self.topView addSubview:_line];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setTitle:@"版块" forState:UIControlStateNormal];
    btn2.frame = CGRectMake(kScreenWidth / 2 + 30, 7, 40, 28);
    btn2.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.topView addSubview:btn2];
    [btn2 addTarget:self action:@selector(two:) forControlEvents:UIControlEventTouchUpInside];
    _aline = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 + 30, 37, 40, 2)];
    _aline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    [self.topView addSubview:_aline];
}

- (void)one:(UIButton *)sender
{
    _forumScrView.contentOffset = CGPointMake(0, 0);
    _line.backgroundColor = [UIColor whiteColor];
    _aline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
}
- (void)two:(UIButton *)sender
{
    _forumScrView.contentOffset = CGPointMake(kScreenWidth, 0);
    _aline.backgroundColor = [UIColor whiteColor];
    _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
}

//给论坛控制器添加scrollView
- (void)addForumScrollView
{
    _forumScrView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight - 64 - 44)];
    _forumScrView.contentSize = CGSizeMake(kScreenWidth * 2, 0);
    _forumScrView.pagingEnabled = YES;
    _forumScrView.bounces = NO;
    [self.view addSubview:_forumScrView];
}
//实现scrollView的代理方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (_forumScrView.contentOffset.x / kScreenWidth == 0) {
        _aline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _line.backgroundColor = [UIColor whiteColor];
    }
    else if(_forumScrView.contentOffset.x / kScreenWidth == 1)
    {
        _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _aline.backgroundColor = [UIColor whiteColor];
    }
}





@end
